package com.yonyou.pmclouds.project.processor;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.runtime.RuntimeEnvironment;
import com.yonyou.pmclouds.project.entity.ProjectVO;
import com.yonyou.pmclouds.team.entity.TeamEnterpriseVO;
import com.yonyou.pmclouds.team.rmiimpl.TeamMaintainForProject;
import com.yonyou.pmclouds.team.rmiitf.TeamEnterpriseMaintain;
import org.apache.commons.lang3.StringUtils;

public class OutterUpdateEnterpriseToTeamProcessor implements SingleProcessor<ProjectVO> {
    private TeamEnterpriseMaintain teamEnterpriseMaintain;
    private String enterprise;

    public OutterUpdateEnterpriseToTeamProcessor(TeamEnterpriseMaintain teamEnterpriseMaintain, String enterprise) {
        this.teamEnterpriseMaintain = teamEnterpriseMaintain;
        this.enterprise = enterprise;
    }

    @Override
    public void process(ProjectVO vo, ProjectVO orig) throws BusinessException {

        if(StringUtils.isEmpty(orig.getManager()) && !StringUtils.isEmpty(vo.getManager())){

            TeamEnterpriseVO teamEnterpriseVO = new TeamEnterpriseVO();
            teamEnterpriseVO.setPkEnterprise(enterprise);
            teamEnterpriseVO.setEntRole(TeamEnterpriseVO.EnterpriseRoleConst.ROLE_OWNER);
            teamEnterpriseVO.setPkTenant(RuntimeEnvironment.getTenantId());

            teamEnterpriseMaintain.addEnterpriseToProject(orig.getPkProject(),new TeamEnterpriseVO[]{teamEnterpriseVO});
        }



    }

}
